#include <vtkSmartPointer.h>
#include <vtkImageReader2.h>
#include <vtkImageData.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkPNGReader.h>
#include <vtkImageReader2Factory.h>



int main(int argc, char *argv[])
{

  //根据类型旋转不同的Reader
  // vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();
  // 更加通用的方法为
  vtkSmartPointer<vtkImageReader2> reader = vtkImageReader2Factory::CreateImageReader2("img/pic1.png");
    // 或者添加文件存在性检查
  if (!reader->CanReadFile("img/pic1.png")) {
    std::cerr << "Cannot read111 file: img/pic1.png" << std::endl;
    return EXIT_FAILURE;
  }
  reader->SetFileName("img/pic1.png");
  reader->Update();

  reader->GetOutput()->Print(std::cout);
  vtkSmartPointer<vtkImageViewer2> viewer = vtkSmartPointer<vtkImageViewer2>::New();
  viewer->SetInputData(reader->GetOutput());
  viewer->Render();
  viewer->GetRenderer()->ResetCamera();
  viewer->GetRenderWindow()->Render();
  viewer->GetRenderWindow()->SetSize(640, 480);
  viewer->GetRenderWindow()->Render();
  vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  //需要设置对应的interactor
  viewer->SetupInteractor(interactor);
  interactor->SetRenderWindow(viewer->GetRenderWindow());
  viewer->Render();
  interactor->Start();
  return EXIT_SUCCESS;
}